import { render, createVNode } from "vue";

import MNotice from "./ErrorDialog.vue";

export default function (options = {}) {
  const { duration = 2500, title, message } = options;

  const mountNode = document.createElement("div");
  const hideNotice = () => {
    let laterTime = 2500;
    if (
      duration &&
      Object.prototype.toString.call(duration) === "[object Number]"
    ) {
      laterTime = duration;
    }
    setTimeout(() => {
      document.body.removeChild(mountNode);
    }, laterTime);
  };

  const app = createVNode(MNotice, {
    title,
    message,
  });

  render(app, mountNode);

  document.body.appendChild(mountNode);

  hideNotice();
}